package com.willpower.eureka.auth;

import com.willpower.eureka.auth.response.Result;
import com.willpower.eureka.auth.response.ResultCode;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: wen-yi;
 * @date: 2021/10/31 16:51;
 * @Description: 403异常处理 无权限方案
 */
@Component("myAccessDeniedHandler")
public class MyAccessDeniedHandler extends JSONAuthentication implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
        Result result = Result.fail(ResultCode.NO_PERMISSION)/*.setMessage(e.getMessage())*/;
        this.WriteJSON(request, response, result);
    }
}
